<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>		
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		
        <script type="text/javascript">
        	var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
			var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        	var store;
            var grid;
			
			var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
			var ctProductFamily = new i18nMessage('../../servlet/CodeTableServlet?name=CtFactoryType');
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/BiFactoryServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			 Ext.onReady(function(){
                
                
                store = new Ext.data.Store({
                    url: '../../servlet/BiFactoryServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'index', 'id', 'nameEN', 'nameCN','departmentCN','departmentEN', 'ctFactoryType', 'labour', 'comment',
					'addressCommercialCN','addressCommercialEN', 'commercialContactCN','commercialContactEN', 'commercialPhone', 'commercialEmail', 'commercialFax',
					'addressFactoryCN','addressFactoryEN', 'factoryContactCN','factoryContactEN', 'factoryPhone', 'factoryEmail', 'factoryFax',
					'hasLoom', 'loomJauge', 'loomQuality', 'loomLabour',
					'hasKnitting', 'knittingJauge', 'knittingQuality', 'knittingLabour',
					'hasElectronic', 'electronicJauge', 'electronicQuality', 'electronicLabour',
					'hasIntarsia', 'intarsiaJauge', 'intarsiaQuality', 'intarsiaLabour',
					'isCarded', 'isSemiWorsted', 'isWorsted', 'isSpinningOther1', 'isSpinningOther2', 'isSpinningOther3',
					'isFibre', 'isHank', 'isBobbin', 'isSpace', 'isDyeingOther1', 'isDyeingOther2', 'isDyeingOther3',
					'isRaw', 'isSolid', 'isChine', 'isTwisted', 'isFancy', 'isYarnOther1', 'isYarnOther2', 'isYarnOther3',
					'isCotton', 'isMercerisedCotton', 'isKapok', 'isLinen', 'isHemp', 'isRamie', 'isWool', 'isCashmere', 'isYack', 'isCamel', 'isSilk', 'isViscose', 'isModal', 'isModal', 'isTencel', 'isBamboo', 'isMilkFibre', 'isAcetate', 'isTriacetate', 'isPolyamid', 'isPolyester', 'isAcrylic', 'isMaterialOther1', 'isMaterialOther2', 'isMaterialOther3', 'isMaterialOther4', 'isMaterialOther5',
					'isNeedle', 'isHand', 'isIntarsiaHand', 'isElectronic', 'isEquipmentOther1', 'isEquipmentOther2', 'isEquipmentOther3',
					'needleCapacity',
					'isHandJauge3', 'isHandJauge5', 'isHandJauge7', 'isHandJauge9', 'isHandJauge12', 'isHandJauge14', 'isHandJauge16', 'isHandJauge18',
					'handJauge3Capacity', 'handJauge5Capacity', 'handJauge7Capacity', 'handJauge9Capacity', 'handJauge12Capacity', 'handJauge14Capacity', 'handJauge16Capacity', 'handJauge18Capacity',
					'isIntarsiaHandJauge3', 'isIntarsiaHandJauge5', 'isIntarsiaHandJauge7', 'isIntarsiaHandJauge9', 'isIntarsiaHandJauge12', 'isIntarsiaHandJauge14', 'isIntarsiaHandJauge16', 'isIntarsiaHandJauge18',
					'intarsiaHandJauge3Capacity', 'intarsiaHandJauge5Capacity', 'intarsiaHandJauge7Capacity', 'intarsiaHandJauge9Capacity', 'intarsiaHandJauge12Capacity', 'intarsiaHandJauge14Capacity', 'intarsiaHandJauge16Capacity', 'intarsiaHandJauge18Capacity',
					'isElectronicJauge3', 'isElectronicJauge5', 'isElectronicJauge7', 'isElectronicJauge9', 'isElectronicJauge12', 'isElectronicJauge14', 'isElectronicJauge16', 'isElectronicJauge18',
					'electronicJauge3Capacity', 'electronicJauge5Capacity', 'electronicJauge7Capacity', 'electronicJauge9Capacity', 'electronicJauge12Capacity', 'electronicJauge14Capacity', 'electronicJauge16Capacity', 'electronicJauge18Capacity',
					'isRemeshing', 'isFulling', 'isIroning', 'isQualityControl', 'isBlendProcessOther1', 'isBlendProcessOther2',
					'remeshingPD', 'fullingPD', 'ironingPD', 'qualityControlPD', 'blendProcessOther1PD', 'blendProcessOther2PD',
					'isJersey', 'isFleece', 'isCoat', 'isInterlock', 'isHuitSerrures', 'isSimpleJacquard', 'isDoubleJacquard', 'isKnittingFamilyOther1', 'isKnittingFamilyOther2',
					'isJerseyJauge14', 'isJerseyJauge16', 'isJerseyJauge18', 'isJerseyJauge20', 'isJerseyJauge22', 'isJerseyJauge24', 'isJerseyJauge28', 'isJerseyJauge32',
					'isFleeceJauge14', 'isFleeceJauge16', 'isFleeceJauge18', 'isFleeceJauge20', 'isFleeceJauge22', 'isFleeceJauge24', 'isFleeceJauge28', 'isFleeceJauge32',
					'isButton', 'isZip', 'isEtiquette', 'isGriffes', 'isHangtags', 'isCuir', 'isAccessoryTypeOther1', 'isAccessoryTypeOther2', 'isAccessoryTypeOther3']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'nameCN'},
					    {type: 'string',  dataIndex: 'nameEN'},
					    {type: 'string', dataIndex: 'departmentCN'},
					    {type: 'string', dataIndex: 'departmentEN'},
					    {
						      type: 'list',  
						      dataIndex: 'ctFactoryType', 
						      options: ctProductFamily.getCtArray()
					    }
					]});
                
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: fcMessage.get('ui.factory.listtitle'),
                    store: store,
					stripeRows: true,
					plugins: filters,
                    height: 560,
                    columns: [{
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: fcMessage.get('ui.factory.name')+'(CN)',
                        dataIndex: 'nameCN',
                        sortable: true
                    }, {
                        header: fcMessage.get('ui.factory.name')+'(FR/EN)',
                        dataIndex: 'nameEN',
                        sortable: true
                    }, {
                        header: fcMessage.get('ui.factory.department') + '(CN)',
                        width: 50,
                        dataIndex: 'departmentCN',
                        sortable: true
                    }, {
                        header: fcMessage.get('ui.factory.department') + '(FR/EN)',
                        width: 50,
                        dataIndex: 'departmentEN',
                        sortable: true
                    }, {
                        header: fcMessage.get('ui.factory.type'),
                        width: 50,
                        dataIndex: 'ctFactoryType',
                        sortable: true
                    },{
                        header: message.get('message.list.eidt'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'biFactory',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
                
                function renderEdit(value, p, record){
                    return String.format('<a href="factory_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
                var detailWin;
                grid.on('rowdblclick', function(grid, rowIndex, e){
                    if (!detailWin) {
                        detailWin = new Ext.Window({
                            title: message.get('message.window.detail'),
                            layout: 'fit',
                            width: 800,
                            height: 480,
                            closeAction: 'hide',
                            plain: true,
                            items: [{
                                id: 'detailPanel',
                                region: 'center',
                                bodyStyle: {
                                    background: '#ffffff',
                                    padding: '7px'
                                },
                                html: message.get('message.window.empty')
                            }]
                        });
                    }
                    
                    detailWin.show(this);
                    var itemTplMarkup = [
						'<table cellspacing="0" id="the-table"><tbody>',
							'<tr><td style="background:#eeeeee;">',
							message.get('message.list.id'),
							'</td><td>{id}</td>',
							'<td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.type'),
							'</td><td colspan="5">{ctFactoryType}</td></tr>',

							'<tr><td style="background:#eeeeee;">',
							fcMessage.get('ui.factory.name') + '(CN)',
							'</td><td>{nameCN}</td>',
							'<td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.department')+ '(CN)',
							'</td><td>{departmentCN}</td>',
							'<td style="background:#eeeeee;">',
							fcMessage.get('ui.factory.name') + '(FR/EN)',
							'</td><td>{nameEN}</td>',
							'<td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.department')+ '(FR/EN)',
							'</td><td>{departmentEN}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.factoryaddress')+ '(CN)',
							'</td><td colspan="7">{addressFactoryCN}</td></tr>',
							'<tr><td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.factoryaddress')+ '(EN)',
							'</td><td colspan="7">{addressFactoryEN}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							message.get('message.edit.linkman') + '(CN)',
							'</td><td colspan="3">{factoryContactCN}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.linkman') + '(FR/EN)',
							'</td><td colspan="3">{factoryContactEN}</td></tr>',

							'<tr><td style="background:#eeeeee; ">',
							message.get('message.edit.phone'),
							'</td><td>{factoryPhone}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.email'),
							'</td><td>{factoryEmail}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.fax'),
							'</td><td colspan="3">{factoryFax}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.commercialaddress') + '(CN)',
							'</td><td colspan="7">{addressCommercialCN}</td></tr>',
							'<tr><td style="background:#eeeeee; ">',
							fcMessage.get('ui.factory.commercialaddress') + '(FR/EN)',
							'</td><td colspan="7">{addressCommercialEN}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							message.get('message.edit.linkman') + '(CN)',
							'</td><td colspan="3">{commercialContactCN}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.linkman') + '(CN)',
							'</td><td colspan="3">{commercialContactCN}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							message.get('message.edit.phone'),
							'</td><td>{commercialPhone}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.email'),
							'</td><td>{commercialEmail}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.fax'),
							'</td><td colspan="3">{commercialFax}</td></tr>',
							
							'<tr><td style="background:#eeeeee; ">',
							message.get('message.edit.labour'),
							'</td><td>{labour}</td>',
							'<td style="background:#eeeeee; ">',
							message.get('message.edit.comment'),
							'</td><td colspan="5">{comment}</td></tr>',
							
						'</tbody></table>'
					
					
					];
                    var itemTpl = new Ext.Template(itemTplMarkup);
                    var detailPanel = Ext.getCmp('detailPanel');
                    itemTpl.overwrite(detailPanel.body, grid.getStore().getAt(rowIndex).data);
                });
                
                
            });
			
			function renderYesno(value, p, record){
				if(value == '01')
					return String.format('<img src="../../images/icons/tick.png" />', value);
				else
					return String.format('<img src="../../images/icons/cross.png"/>', value);
            }
                    
                    
        </script>
    </head>
    <body>
        <div id="biFactory">
        </div>
    </body>
</html>
